<?php
ob_start();
session_start();

$id=$_SESSION['id'];

 include_once('restconnection.php'); 
     
     if(isset($client)){  
      
        //retrive base url 
        $url = $_SESSION['basic_url'];
        //add service url
        $service_url="/Passion?";
        //params url
        $params = array('id'=>$id); 
        //params connection
        $ctx = stream_context_create(array('http' => array('timeout' => 5))); 
        //send GET request
        $final_url = $url.$service_url."id=".$params['id'];
        //print_r($final_url); break;
        $output = @file_get_contents($final_url,0,$ctx);
        //parse JSON output
      //  print_r($url.$service_url."id=".$params['id']); break;
        $data = json_decode($output);
        //var_dump($output); break;
        $webResult = $data->PassionResult;
       // print_r($webResult); break;
        

        //split and riorganize Facebook message_post  
        if($webResult[0]!= null){   
        
             $get=$webResult;
             
            // print_r($get); break;
              //number of all records devono essere 11
             $num_records=count($get);
            // echo$num_records; 
            // break;
         
             if($num_records!=1){
                for($i=0;$i<$num_records;$i++){
                  
                           
                        $split = explode("+-+",$get[$i]);
                        
                       // print_r($split[0]); break;
                        
                        $tag[$i]=$split[0];                    
                        
                        $social[$i]=$split[1];
                        
                        $passion[$i]=$split[2];
                                                   
                  
  
                }//for
                        
             
             }else{
                
                        $split = explode("+-+",$get[0]);
                        
                        $tag[0]=$split[0];                    
                        
                        $social[0]=$split[1];
                        
                        $passion[0]=$split[2];
              }    
    
 
?>

<head>
    <title>Passion</title>
    <link rel="stylesheet" type="text/css" href="css/table_css.css">
</head>

<body style="background-color: white; text-align: center"
<label>STATISTIC FOR YOUR CONNECTED SOCIAL NETWORK!</label>
<br /><br />

<a href="general_stats.php" ><label>Panoramic view </label></a><a href="interaction.php" ><label>| Interaction </label></a> <a href="engagement.php" ><label>| Engagement </label></a> <strong><label>| Passion </label></strong>

<br/> <br/> 

<label style="font-size: 30px;">Passion</label>

<br /><br /><br />

<?php $targetUrl = 'passion_graph.php?';

for($i=1;$i<=$num_records;$i++){
   
    $targetUrl .= "user" . $i . "=" . $tag[$i-1] . "&passion". $i ."=" .$passion[$i-1].'&'; 
   
    
}

$targetUrl = substr($targetUrl, 0, -1); 

$targetUrl .= "&num_user=".$num_records;

$targetUrl= str_replace(",",".", $targetUrl);

//print_r($targetUrl); 
echo "<img src='$targetUrl'>";  ?>

<br />

<label> MORE DETAILS</label>
<br />
    
<div class="CSSTableGenerator" >
<table width="100%" border="1" cellpadding="10" cellspacing="1">
    <tr>
        <td width="5%">Social</td>
        <td>Tagger</td>
        <td title="% of Passion that generates a single user on a social network. Formulas is # of mention for each user divided by # of # of total mention on my brand">
            Passion</td>
        </tr>

<?php

   
    
                for($i=0;$i<$num_records;$i++){
                
                   
        ?>          <tr> 
                    <td>
                        <?php 
                            if($social[$i] == "Facebook") echo"<img style='width:30px;'  src='img/fb_icon.png' title='$social[$i]' alt='$social[$i]' />";
                            if($social[$i] == "Google")  echo"<img style='width:30px;'   src='img/g+_icon.png' title='$social[$i]' alt='$social[$i]' />";
                            if($social[$i] == "Twitter") echo"<img  style='width:30px;'  src='img/tw_icon.png' title='$social[$i]' alt='$social[$i]' />";
                            if($social[$i] == "Pinterest")  echo"";
                            if($social[$i] == "Linkedin")  echo"";
                            if($social[$i] == "Foursquare") echo"";    
                            
                        ?> 
                        
                    </td>
                    <td><?php echo$tag[$i];?></td>   
                    <td><?php echo$passion[$i];?>%</td> 
                    </tr>
        <?php
                 
                }//for
                
  
                                 
          }else{
              ?>
              <label style="margin-left:0px;">There are no posts</label>
            
              <?php  
          }
            
     }//isset(client)    
   
            
 ?>  

 
</table>
</div>    
</body>
